{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<section class="panel">
    <header class="panel-heading">
        <h4>参数配置</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <table class="table table-bordered table-striped no-margin">
            <thead>
            <tr>
                <th class="text-center">序号</th>
                <th class="text-center">名称</th>
                <th class="text-center">key值</th>
                <th class="text-center">value值</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $key=>$config}
            <tr>
                <td class="text-center" style="vertical-align: middle; ">{$key+1}</td>
                <td class="text-center" style="vertical-align: middle; ">{$config->name}</td>
                <td class="text-center" style="vertical-align: middle; ">{$config->key}</td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="text" id="{$config->key}" style="text-align: center" class="form-control"
                           value="{$config->value}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <a onclick="updateConfig(this)" data-key="{$config->key}" class="btn btn-xs btn-primary">确认修改</a>
                </td>
            </tr>
            {/foreach}
            <tr>
                <td class="text-center" style="vertical-align: middle; "></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="text"  style="text-align: center" id="name" class="form-control" value=""></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="text"  style="text-align: center" id="key" class="form-control" value=""></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="text"  style="text-align: center" id='value' class="form-control" value="">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <a onclick="addConfig(this)" class="btn btn-xs btn-primary">确认添加</a>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
</section>
{/block}

{block name="footer"}

<script>
    function addConfig(e) {
        var name = $('#name').val();
        var key = $('#key').val();
        var value = $('#value').val();

        $.post("{:url('legal/setadd')}", {name: name,key: key, value: value}, function (data) {
            if (data.code == 1) {
                main.waringAlert(data.message);
            } else {
                main.waringAlert(data.message);
                window.location.reload();
            }
        }, 'json')
    }
    function updateConfig(e) {
        var key = $(e).attr('data-key');
        var value = $("#" + key).val();
        $.post("{:url('legal/setsave')}", {key: key, value: value}, function (data) {
            if (data.code == 1) {
                main.waringAlert(data.message);
            } else {
                main.waringAlert(data.message);
                window.location.reload();
            }
        }, 'json')
    }
</script>
{/block}